using System;
using System.Web;

namespace SystemFrameworks.Util
{
	/// <summary>
	/// Summary description for StringUtil.
	/// </summary>s
	public class StringUtil
	{
		public StringUtil()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		/// <summary>
		///	Delete the last  Comma
		/// </summary>
		/// <param name="origin"></param>
		/// <returns></returns>
		public static string DelLastComma(string origin)
		{
			if(origin.IndexOf(",") == -1)
			{
				return origin;
			}
			return origin.Substring(0,origin.LastIndexOf(","));
		}

		public static bool checkStringNull(string strValue)
		{
			if(strValue==null || strValue.Length==0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		///  delete the visible char
		/// </summary>
		/// <param name="sourceString"></param>
		/// <returns></returns>
		public static string DeleteUnVisibleChar(string sourceString)
		{
			System.Text.StringBuilder sBuilder = new System.Text.StringBuilder(131);
			for(int i = 0;i < sourceString.Length; i++)
			{
				int Unicode = sourceString[i];
				if(Unicode >= 16)
				{
					sBuilder.Append(sourceString[i].ToString());
				}				
			}
			return sBuilder.ToString();
		}

		/// <summary>
		/// Convert a string into an HTML-encoded string
		/// </summary>
		/// <param name="s"></param>
		/// <returns></returns>
		public static string HtmlEncode( string s )
		{
			string result = HttpUtility.HtmlEncode( s );
			result = result.Replace( "\r\n", "<br>" );
		//	result = result.Replace( " ", "&nbsp;" );
			return result;
		}
	}
}
